Skip to content

fix: validate k shape when dims is omitted - #14329

Closed
Planeshifter wants to merge 1 commit into
developfrom
philipp/ci-fix-circshift-broadcast-validation-2026-08-16
Closed

fix: validate k shape when dims is omitted#14329
Planeshifter wants to merge 1 commit into
developfrom
philipp/ci-fix-circshift-broadcast-validation-2026-08-16

Conversation

@Planeshifter

@Planeshifter Planeshifter commented Aug 16, 2026

Copy link
Copy Markdown
Member

Description

This pull request:

  • validates the shape of an ndarray-valued k argument against maybeBroadcastArray( k, [] ) in the two circshift code paths that omit the dims option, matching the validation already applied in the dims-provided path.

Failing run: https://github.com/stdlib-js/stdlib/actions/runs/31938255523 (job Node.js v16 on workflow macos_test; see raw logs)

Symptom: circshift( x, k ) and circshift( x, k, {} ) did not throw for a k shape that is not broadcast-compatible with the implied zero-dimensional target (e.g. k shape [4], [2,2,2], or [0] against x shape [2,2]), contrary to the documented contract.

Root cause: the no-dims branches for an ndarray k passed it straight through to base() unvalidated. In practice this was worse than a missing throw: an incompatible k silently no-op'd (returned x unmodified, ignoring k entirely) rather than either shifting correctly or raising an error.

Related Issues

This pull request has the following related issues:

  • None.

Questions

No.

Other

Validated by three independent reviewers (correctness, regression scope, style/conventions); all approved. Reviewer B ran the package's full test suite directly (270/270 passing, including the two previously-failing blocks). No fan-out: circshift is a leaf package with no in-repo callers passing an ndarray k.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

  • Yes

  • No

  • Code generation (e.g., when writing an implementation or fixing a bug)

  • Test/benchmark generation

  • Documentation (including examples)

  • Research and understanding

Disclosure

This PR was proposed by Claude Code as part of an automated CI-failure investigation routine. The root-cause analysis, the fix, and three-reviewer validation (correctness, regression scope, style/conventions) were produced by Claude Code. Final review and merge decision rest with the maintainers.


@stdlib-js/reviewers


Generated by Claude Code

…itted

The job `Node.js v16` on workflow `macos_test` failed on develop with
6 tape assertion failures under "throws an error if provided a `k`
argument which is not broadcast-compatible": `circshift( x, k )` and
`circshift( x, k, {} )` did not throw for `k` shapes `[4]`, `[2,2,2]`,
and `[0]` against a `[2,2]` input, contrary to the documented
contract. Root cause: in `lib/main.js`, the no-`dims` branches for an
ndarray-valued `k` (`k_ndarray` in both the 2-argument and options-
argument call forms) passed `k` straight through to `base()` without
validating that its shape is broadcast-compatible with the implied
zero-dimensional target shape, unlike the `dims`-provided branch,
which already validates via `maybeBroadcastArray`. This commit applies
the same `maybeBroadcastArray( k, [] )` validation to both no-`dims`
branches, matching the idiom already used elsewhere in the codebase
(e.g. `@stdlib/blas/ext/copy-within/lib/broadcast_index.js`) and
restoring the documented `@throws` contract without changing behavior
for already-valid inputs (a 0-dimensional `k` continues to pass
through `maybeBroadcastArray` unchanged).

Ref: https://github.com/stdlib-js/stdlib/actions/runs/31938255523
@stdlib-bot stdlib-bot added the BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). label Aug 16, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
blas/ext/circshift $\\color{green}264/264$
$\\color{green}+100.00\\%$
$\\color{green}20/20$
$\\color{green}+100.00\\%$
$\\color{green}1/1$
$\\color{green}+100.00\\%$
$\\color{green}264/264$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

@Planeshifter
Planeshifter marked this pull request as ready for review August 16, 2026 18:09
@Planeshifter
Planeshifter requested review from a team and kgryte August 16, 2026 18:09
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Aug 16, 2026
@Planeshifter Planeshifter changed the title fix(@stdlib/blas/ext/circshift): validate k shape when dims is omitted fix: validate k shape when dims is omitted Aug 16, 2026
@kgryte

kgryte commented Aug 16, 2026

Copy link
Copy Markdown
Member

This is a duplicate.

Copy link
Copy Markdown
Member Author

Confirmed — #14228 already covers this exact fix for circshift (and additionally sort/sorthp, which share the same defect). Closing this in favor of #14228.


Generated by Claude Code

@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants